<%@page import="com.sun.mail.imap.IMAPFolder"%>
<%@page import="javax.mail.Message"%>
<%@page import="javax.mail.MessagingException"%>
<%@page import="javax.mail.Folder"%>
<%@page import="javax.mail.NoSuchProviderException"%>
<%@page import="javax.mail.Store"%>
<%@page import="javax.mail.Session"%>
<%@page import="vo.mailVO"%>
<%@page import="dto.mailDTO"%>
<%@page import="java.util.Properties"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Mail Menu :: 메일 메뉴</title>
<link rel="stylesheet" href = '../css/left_menu.css'>
<script src = '../js/mail.js'></script>
</head>
<body>
<jsp:useBean id="vo" class="vo.mailVO" scope="page"/>
<jsp:setProperty property="*" name="vo"/>

<% 	
	mailDTO dto = new mailDTO();
	String m_id2 = (String)session.getAttribute("sessionMid");
	vo.setM_id(m_id2);
	mailVO v = dto.emailInfo(vo);
	String protocol = "imap"; 
	Properties proper = dto.getServerProperties(v);
	Session session2 = Session.getDefaultInstance(proper);
	
	 try{
			Store store = session2.getStore(protocol);
	        store.connect(v.getEmail_address(), v.getEmail_pwd());

	        Folder folderInbox = store.getFolder("INBOX");
	        folderInbox.open(Folder.READ_ONLY);	
	        
	        javax.mail.Folder [] folders = store.getDefaultFolder().list("*");
	        Message[] messages = folderInbox.getMessages();
%>	
	
	<form name = 'MenuhiddenFrm' method='post'>
		<input type='hidden' name='m_id' value="<%=v.getM_id()%>"/>
		<input type="hidden" name="email_list"/>
		<input type="hidden" name="email_address" value="<%=v.getEmail_address()%>">
		<input type="hidden" name="email_pwd" value="<%=v.getEmail_pwd()%>"/>
		<input type="hidden" name="e_name" value="<%=v.getE_name()%>"/>
		<input type="hidden" name="email_sender" value="<%=v.getEmail_sender()%>"/>
	</form>	
 	<div class="left_menu">	
		<div id="menu_title"><img src = '../images/menu_mail.png'></div>
		
		<div class = 'lal'>
			<div class="ldl"><img src = '../images/folder.png' width = '10%' height='10%'><a href="#" onclick="goList('INBOX')"> 받은메일함
			</a></div>	
		</div>
		
		<div class = 'lal'>
			<div class="ldl"><img src = '../images/folder.png' width = '10%' height='10%'><a href="#" onclick="goInput()"> 메일 쓰기</a></div>	
		</div>
		
		<div class = 'lal'>
			<div class="ldl"><img src = '../images/folder.png' width = '10%' height='10%'><a href="#" onclick="goList('Sent Messages')"> 보낸 편지함</a></div>	
		</div>
		
		<div class = 'lal'>
			<div class = 'ldl'><img src = '../images/folder.png' width = '10%' height='10%'> 메일함
		
	 <%
        for (javax.mail.Folder folder : folders) {
        	if ((folder.getType() & javax.mail.Folder.HOLDS_MESSAGES) != 0) { 
        		if(!folder.getFullName().equals("Deleted Messages") && 
        				!folder.getFullName().equals("Sent Messages") &&
        				!folder.getFullName().equals("INBOX")){%> 
        		
        	<div class = 'lcl'>	
        		<img src = '../images/mail.png' width = '10%' height='10%'><a href="#" onclick="goList('<%=folder.getFullName()%>')">
	     	<% out.println(folder.getFullName() + " (" + folder.getUnreadMessageCount() + "/"+folder.getMessageCount()+") <br/>"); %>
	     	</a></div>
	     	<%
        		}
	        }
	    }%>
	    </div>
	 </div>   
	 <div class = 'lal'>
			<div class="ldl"><img src = '../images/folder.png' width = '10%' height='10%'><a href="#" onclick="goList('Deleted Messages')"> 휴지통
			</a></div>	
	</div>   
	    
       
	<% }catch (NoSuchProviderException ex) {
        System.out.println("No provider for protocol: " + v.getProtocol());
        ex.printStackTrace();
    } catch (MessagingException ex) {
        System.out.println("Could not connect to the message store");
        ex.printStackTrace();
    }
	
	%> 
	
		
	
</div>			
</body>
</html>